/*package triIndex.btree;

import java.util.*;

import triStorage.*;

public class BBranch extends BNode {

	Vector<Integer> childblk;

	BBranch(int order, NodeFactory factory) {
		this.order = order;
		this.leastChildNum = (order + 1) / 2;
		this.factory = factory;
	}

	BBranch(int order, int nodeId, int nextPageId, NodeFactory factory) {
		this.order = order;
		this.leastChildNum = (order + 1) / 2;
		this.keys = new Vector<Integer>();
		this.values = new Vector<Integer>();
		this.nodeId = nodeId;
		this.factory = factory;
		this.childblk =  new Vector<Integer>();
	}

	@Override
	public int find(int key) {
		for (int i = 0; i < childnum; ++i)
			if (key <= keys.get(i)) 
				return getChild(i).find(key);
		return BTree.ERROR_CODE;
	}

	private BNode getChild(int index) {
		BNode child = factory.getNode(childblk.get(index));
		return child;
	}
	
	@Override
	public BNode[] insert(int key, int value) {
		BNode[] nodes;
		BNode[] ret;

		int index;
		for (index = 0; index < childnum - 1; ++index)
			if (key < keys.get(index))
				break;

		if (index < childnum - 1)
			System.out.println("Bbranch " + "insert into " + index + " " + keys.get(index).toString());
		else System.out.println("Bbranch " + "insert into " + index);
		BNode child = getChild(index);
		nodes = child.insert(key, value);

		if (nodes.length > 1) {
			++childnum;
			childblk.add(index + 1, nodes[1].nodeId);

			if (nodes[0] instanceof BLeaf && nodes[1] instanceof BLeaf) {
				keys.add(index, nodes[1].keys.firstElement());
				values.add(index, nodes[1].values.firstElement());
			}
			else if (nodes[0] instanceof BBranch && nodes[1] instanceof BBranch) {
				keys.add(index, nodes[0].keys.remove(leastChildNum - 1));
				values.add(index, nodes[0].values.remove(leastChildNum- 1));
			}
			else 
				System.err.println("should not be reached ! " + "index.btree.Branch");
		}

		if (childnum > order) 
			ret = split();
		else {
			ret = new BNode[1];
			ret[0] = this;
		}
		return ret;
	}

	public BNode[] split() {
		BBranch branch = factory.createNewBranch(this.order);
		//BBranch branch = new BBranch(keytype, keysize, filename, tx, file);	

		for (int i = leastChildNum; i < childnum - 1; ++i) {
			branch.keys.add(keys.remove(leastChildNum));
			branch.values.add(values.remove(leastChildNum));
			branch.childblk.add(childblk.remove(leastChildNum));
		}
		
		branch.childblk.add(childblk.remove(leastChildNum));
		
		branch.childnum = childnum - leastChildNum;
		childnum = leastChildNum;

		BNode[] ret = new BNode[2];
		ret[0] = this;
		ret[1] = branch;
		return ret;
	}

	@Override
	public void flush(IWriter writer) {
		writer.appendInt(nodeId);
		writer.appendInt(BNode.BRANCH);
		writer.appendInt(childnum);
		
		for (int i = 0; i < childnum - 1; ++i) {
			writer.appendInt(childblk.get(i));
			writer.appendInt(keys.get(i));
			writer.appendInt(values.get(i));
		}
		
		writer.appendInt(childblk.get(childnum - 1));
	}

	@Override
	public void load(IReader reader) {
		this.nodeId = reader.readInt();
		if (reader.readInt() != BNode.BRANCH)
			System.err.println("node " + nodeId + "is not branch!");
		childnum = reader.readInt();
		
		childblk = new Vector<Integer>();
		keys = new Vector<Integer>(childnum - 1);
		values = new Vector<Integer>(childnum - 1);
		childblk =  new Vector<Integer>(childnum);

		for (int i = 0; i < childnum - 1; ++i) {
			childblk.add(reader.readInt());
			keys.add(reader.readInt());
			values.add(reader.readInt());
		}

		childblk.add(reader.readInt());
	}
	
	public void outputSelf(String s) {
		System.out.println(s + "------Bbranch-----");
		for (int i = 0 ; i < childnum ; ++i) {
			if (i < childnum - 1)
				System.out.println(s + "----child " + i + "------" + keys.get(i).toString() + ","
					+ values.get(i));
			else
				System.out.println(s + "----child " + i + "------");				
			getChild(i).outputSelf(s +"   ");
		}
		System.out.println(s + "------Bbranch  over-----");
	}

}
*/